package com.example.cognitivesystemserver.service;

import com.example.cognitivesystemserver.mapper.EvaluationMapper;
import com.example.cognitivesystemserver.pojo.Evaluation;
import com.example.cognitivesystemserver.utils.AssertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EvaluationServiceImpl implements EvaluationService{
    @Autowired
    private EvaluationMapper evaluationMapper;


    @Override
    public Evaluation getEvaluationRes(String stuId) {
        return this.evaluationMapper.getEvaluationRes(stuId);
    }

    @Override
    public void saveEvalRes(Evaluation evaluation) {
        //根据学号判断先前是否测评
        String stuId = evaluation.getStuId();
        Evaluation evaluationRes = evaluationMapper.getEvaluationRes(stuId);
        if (null==evaluationRes){
            //未创建测评结果
            evaluationMapper.insertEvalRes(evaluation);

        }else {
            //已创建测评结果
            //更新测评结果
            evaluation.setId(evaluationRes.getId());
            evaluationMapper.updateEvalRes(evaluation);
        }
    }

    @Override
    public List<Evaluation> getAllEval() {
        return evaluationMapper.getAllEval();
    }
}
